package com.qf.netty.handler;

import com.google.gson.Gson;
import com.qf.entity.netty.ChatMsg;
import com.qf.entity.netty.ConnMsg;
import com.qf.entity.netty.ShutDownMsg;
import com.qf.netty.channel.ChannelGroup;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @Description:
 * @Author: xbb
 * @Date:2020/4/21
 */
public class ChatHandler extends SimpleChannelInboundHandler<ChatMsg> {

    private RabbitTemplate rabbitTemplate;

    public ChatHandler(RabbitTemplate rabbitTemplate){
        this.rabbitTemplate = rabbitTemplate;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ChatMsg chatMsg) throws Exception {
        System.out.println("用户聊天的信息:"+chatMsg);

        //消息入库

        //转发
        rabbitTemplate.convertAndSend("wx_exchange","",chatMsg);
    }
}
